//@ts-nocheck
import { defineStore } from "pinia";

interface iProps {
  mapAction: string;
  addPipePoint: null | { lat: number; lng: number };
}

export const useMapStore = defineStore("map", {
  state: () => {
    return {
      mapAction: "", // 管网编辑-执行的动作
      selectedMarkers: [], // 地图上选中的点位
      addedPipePoint: null, // 新增的管点
      isShowPipeInfoList: false, // 是否显示管点信息列表
      addedPipeLines: null, // 地图上新增的管线
      lineDepth: 0, // 管段的平均深度
      addedPipePointOnLine: null, // 线上加点
      pointDevideLine: null, // 点打断线
      tmpPipeLines: [], // 临时辅助线
      startPointInfo: null,
      editingPipePoint: null,
      editingPipeLine: null,
      areaCoordinates: "",
      areaTypeId: null,
      canSelectPipePointFlag: false,
      canSelectAreaFlag: false,
      selectedInspectionNode: null,
      splitLines: [],
      editingInspectionRoute: null,
      mapCenter: [31.2, 121.2],
    };
  },

  actions: {
    setMapAction(action: string) {
      this.mapAction = action;
    },
    addSelectedMarkers(obj: object) {
      const list = [...this.selectedMarkers, obj];
      this.selectedMarkers = list.slice(list.length - 2);
    },
    clearSelectedMarkers() {
      this.selectedMarkers = [];
    },
    setAddedPipePoint(point: { lat: number; lng: number } | null) {
      this.addedPipePoint = point;
    },
    setShowPipeInfoListFlag(flag: boolean) {
      this.isShowPipeInfoList = flag;
    },
    setAddedPipeLines(lines: Array<any> | null) {
      this.addedPipeLines = lines;
    },
    setTmpPipeLines(positions: Array<any>) {
      this.tmpPipeLines = positions;
    },
    setAddedPipePointOnLine(point: { lat: number; lng: number } | null) {
      this.addedPipePointOnLine = point && { ...point };
    },
    setPointDevideLine(data) {
      this.pointDevideLine = data;
    },
    setStartPointInfo(latlng) {
      this.startPointInfo = latlng;
    },
    setEditingPipePoint(point: any) {
      this.editingPipePoint = point;
    },
    setEditingPipeLine(line: any) {
      this.editingPipeLine = line;
    },
    setAreaCoordinates(coords: string) {
      this.areaCoordinates = coords;
    },
    setAreaTypeId(typeId: number) {
      this.areaTypeId = typeId;
    },
    setCanSelectPipePointFlag(flag: boolean) {
      this.canSelectPipePointFlag = flag;
    },
    setCanSelectAreaFlag(flag: boolean) {
      this.canSelectAreaFlag = flag;
    },
    setSelectedInspectionNode(obj: any) {
      this.selectedInspectionNode = obj;
    },
    setSplitLines(list: Array<any>) {
      this.splitLines = list;
    },
    setEditingInspectionRoute(route: any) {
      this.editingInspectionRoute = route;
    },
    setLineDepth(value: number) {
      this.lineDepth = value;
    },
    setMapCenter(list: any) {
      this.mapCenter = list;
    },
  },
});
